﻿using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.Xpo;
using DevExpress.Xpo.Metadata;
using System.Collections.Specialized;

namespace OT.Dev
{
    public class EntityMeta<E>
    {
        public EntityMeta(Session xpo)
        {
            classInfo = xpo.GetClassInfo<E>();
        }

        XPClassInfo classInfo;

        public string TableName
        {
            get
            {
                return classInfo.TableName;
            }
        }

        public string KeyProperty
        {
            get
            {
                return classInfo.KeyProperty.Name;
            }
        }


        public void SetEntityProperty(E entity, OrderedDictionary dict)
        {
            foreach (XPMemberInfo prop in classInfo.OwnMembers)
            {
                if (!dict.Contains(prop.Name))
                    continue;

                prop.SetValue(entity, dict[prop.Name]);
            }
        }
    }
}
